package com.example.demo.Blog;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;

import static java.lang.Thread.sleep;

public class BlogCases extends InitAndEnd{
    /*
    * 输入正确的账号，密码登录成功
    * */
    @Test
    void test01() {
        System.out.println("dadaddad");
    }

    @Test
    void LoginSuccess() throws InterruptedException {
        //打开博客登录页面
        webDriver.get("http://localhost:8080/login.html");
        sleep(3000);
        //输入账号admin
        webDriver.findElement(By.cssSelector("#username")).sendKeys("jiaoao");
        //输入密码 123
        webDriver.findElement(By.cssSelector("#password")).sendKeys("123");
        sleep(3000);
        //点击提交按钮
        webDriver.findElement(By.cssSelector("#submit")).click();
        sleep(3000);
        // 跳转到列表页
        //获取到当前页面的 url 如果url 是正确的则测试通过
        String cur_url = webDriver.getCurrentUrl();
        Assertions.assertEquals("http://localhost:8080/myblog_list.html", cur_url);
        //列表页展示用户信息是admin
        //用户名是 admin 则测试通过
        sleep(3000);
        webDriver.findElement(By.cssSelector("#artlist > div:nth-child(1) > a:nth-child(4)")).click();
        String cur_admin = webDriver.findElement(By.cssSelector("#author2")).getText();
        Assertions.assertEquals("jiaoao", cur_admin);
    }
}
